package week3;

import java.util.ArrayList;
import java.util.List;

public class Ex24 {
    public  static int fac(int x){
        if (x == 0) return 1;
        else return x * fac(x-1);
    }
    public static void main(String[] args) {
        int n = 1000000;
        int[] ans = new int[10];
        List<Integer> tmp = new ArrayList<>();
        for (int i = 0; i < 10; ++i)
            tmp.add(i);
        for (int i = 0; i < ans.length; ++i){
            int m = fac(9-i);
            if (n % m == 0) {
                if (n == 0){
                    for (int j = tmp.size()-1; j >= 0; j--){
                        ans[i++] = tmp.get(j);
                    }
                }else {
                    ans[i] = tmp.get(n / m - 1);
                    tmp.remove(n / m - 1);
                }
            } else {
                ans[i] = tmp.get(n / m);
                tmp.remove(n / m);
            }

            n %= m;
        }
        for (int a : ans)
            System.out.print(a);
    }
}
